﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace Kalficom
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
            conf.Icon(this, true);
        }

        Query.qry_User query = new Query.qry_User();
        Libraies.msg msg = new Libraies.msg();

        private void btnContrats_Click(object sender, EventArgs e)
        {
            if (!bool.Parse(new Libraies.db().ExecuteScalar(string.Format(query.scalarIsContart, conf.CurUser))))
            {
                MessageBox.Show(msg.permissionMsg, msg.captionMsg, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            (new frmContract()).ShowDialog();
        }

        private void btnUser_Click(object sender, EventArgs e)
        {
            if (!bool.Parse(new Libraies.db().ExecuteScalar(string.Format(query.scalarIsAdmin, conf.CurUser))))
            {
                MessageBox.Show(msg.permissionMsg, msg.captionMsg, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            (new frmUser()).ShowDialog();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Maximized;            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            (new Forms.frmGeographicZone()).ShowDialog();
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
           // if (MessageBox.Show(msg.exitMsg, msg.captionMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
            //{ e.Cancel = true; }
            conf.CurUser = 0;
            Application.ExitThread();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSystemParametter_Click(object sender, EventArgs e)
        {
            (new Forms.frmSystemParamtters()).ShowDialog();
        }

        private void btnImportCalypso_Click(object sender, EventArgs e)
        {
            if (!bool.Parse(new Libraies.db().ExecuteScalar(string.Format(query.scalarIsCalypso, conf.CurUser))))
            {
                MessageBox.Show(msg.permissionMsg, msg.captionMsg, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Process.Start(new Libraies.db().ExecuteScalar(string.Format(new Query.qry_system_parameter().scalar, 3)));
        }

        
    }
}
